//
//  USDefaultSettingController.m
//  us
//
//  Created by devkarry on 2025/5/6.
//

#import "USDefaultSettingController.h"

@interface USDefaultSettingController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSArray <DTItem *>*items;

@end

@implementation USDefaultSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"偏好设置";
    
    self.us_tableView.dataSource = self;
    self.us_tableView.delegate = self;
    
    DTItem *g_item0 = [DTItem itemWithTitle:nil image:nil tag:0 identifier:@"g_item0" handle:nil];
    
    DTItem *feedback = [DTItem itemWithTitle:@"触感反馈" image:nil tag:0 identifier:@"feedback" handle:nil];
    
    g_item0.items = @[feedback];
    
    self.items = @[g_item0];
    
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.items.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.items[section].items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [UITableViewCell us_defaultCell];
    
    DTItem *item = self.items[indexPath.section].items[indexPath.row];
    
    cell.textLabel.text = item.title;
    
    if ([item.identifier isEqualToString:@"feedback"]) {
        
        [cell us_setAccessorySwitchisSelected:[[NSUserDefaults standardUserDefaults]boolForKey:USPrefKey_EnableFeedback] action:^(BOOL selected) {
        
            [[NSUserDefaults standardUserDefaults]setBool:selected forKey:USPrefKey_EnableFeedback];
            [[NSUserDefaults standardUserDefaults]synchronize];
            if (selected) {
                [USFeedbackTool notifySuccess];
            }
            
        }];
        
    }
    
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [UITableViewCell us_defaultCellRowHeight];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
